package com.moduleSys.utils.string;

import java.util.Random;

public class GenerateRandomNumber {
    public GenerateRandomNumber() {
    }

    public static void main(String[] args) {
        System.out.println("生成的10为随机数为：" + getCharAndNumr(20));
    }

    public static String getCharAndNumr(int length) {
        String charAndNumr = "";
        Random random = new Random();

        for(int i = 0; i < length; ++i) {
            String charOrNum = random.nextInt(2) % 2 == 0?"char":"num";
            if("char".equalsIgnoreCase(charOrNum)) {
                int choice = random.nextInt(2) % 2 == 0?65:97;
                charAndNumr = charAndNumr + (char)(choice + random.nextInt(26));
            } else if("num".equalsIgnoreCase(charOrNum)) {
                charAndNumr = charAndNumr + String.valueOf(random.nextInt(10));
            }
        }

        return charAndNumr;
    }
}
